package com.group3.group3.department.control;
/**
 * Created with IntelliJ IDEA.
 *
 * @Author: Tom
 * @Date: 2022/05/19/18:14
 * @Description:
 */

/**
 *@ClassName departmentController
 *@Description
 *@Author 王琛
 *@Date 2022/5/19 18:14
 @Version 1.0
 */


import com.group3.group3.common.control.BaseController;
import com.group3.group3.department.entity.SearchDepartmentEntity;
import com.group3.group3.mybatis.entity.PtDepartmentEntity;
import com.group3.group3.mybatis.flexigrid.PadingRstType;
import com.group3.group3.mybatis.flexigrid.PagingBean;
import org.apache.logging.log4j.LogManager;
import org.apache.logging.log4j.Logger;
import org.springframework.context.MessageSource;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.ResponseBody;

import javax.annotation.Resource;
import java.util.UUID;

@Controller
@RequestMapping("/department")
public class DepartmentController extends BaseController {
    private Logger logger =  LogManager.getLogger(this.getClass().getName());

    @Resource
    private com.group3.group3.department.service.DepartmentService departmentService;

    @Resource
    private MessageSource messageSource;

    @RequestMapping("/departmentPage")
    public String departmentPage(){
        return "department/departmentPage";
    }

    @RequestMapping("/getDepartmentInfolistByPage")
    @ResponseBody
    public PadingRstType<PtDepartmentEntity> getDepartmentInfoListByPage(SearchDepartmentEntity search, PagingBean paging){
        logger.info(search);
        PadingRstType<PtDepartmentEntity> ptDepartmentEntityPadingRstType = departmentService.getDepartmentInfoListByPage(search,paging);
        return ptDepartmentEntityPadingRstType;
    }

    @RequestMapping("/saveMenuByDepartmentId")
    @ResponseBody
    public String saveMenuByDepartmentId(@RequestParam("depUuid") String depUuid, @RequestParam("menuIds") String menuIds){
        logger.info("depUuid:" + depUuid + " menuIds:" + menuIds);
        departmentService.saveMenuByDepartmentId(depUuid,menuIds);
        return getSuccessMessag("user.allocat.department.success");
    }

    @RequestMapping("/addDepartmentById")
    @ResponseBody
    public String addDepartmentById(PtDepartmentEntity entity){

        logger.info(entity);
        String uuid = UUID.randomUUID().toString().replace("-", "");
        entity.setDepUuid(uuid);

        entity.setDelFlag("0");

        departmentService.addDepartmentById(entity);
        return getSuccessMessag("department.add.success");
    }


}
